package com.qhp.androidsocket;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TabHost;

        public class MainTabActivity extends TabActivity implements OnCheckedChangeListener {

            private TabHost mTabHost;
            private Intent mAIntent;
            private Intent mBIntent;

            /**
             * Called when the activity is first created.
             */
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
                setContentView(R.layout.content_main_tab);
                getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
                this.mAIntent = new Intent(this, IndexActivity.class);
                this.mBIntent = new Intent(this, PhoneActivity.class);

                ((RadioButton) findViewById(R.id.radio_button0))
                        .setOnCheckedChangeListener(this);
                ((RadioButton) findViewById(R.id.radio_button1))
                        .setOnCheckedChangeListener(this);
                setupIntent();
            }

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    switch (buttonView.getId()) {
                        case R.id.radio_button0:
                            this.mTabHost.setCurrentTabByTag("A_TAB");
                            break;
                        case R.id.radio_button1:
                            this.mTabHost.setCurrentTabByTag("B_TAB");
                            break;
                    }
                }

            }

            private void setupIntent() {
                this.mTabHost = getTabHost();
                TabHost localTabHost = this.mTabHost;

                localTabHost.addTab(buildTabSpec("A_TAB", R.string.main_home,
                        R.drawable.home, this.mAIntent));

                localTabHost.addTab(buildTabSpec("B_TAB", R.string.main_news,
                        R.drawable.setting, this.mBIntent));

            }

            private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
                                                 final Intent content) {
                return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel),
                        getResources().getDrawable(resIcon)).setContent(content);
            }
        }

